package com.jobpass.common.data;

import com.jobpass.constant.ResponseCode;
import lombok.Data;

@Data
public class ResultData {

    private boolean status;

    private String code;

    private String msg;

    private Object data;

    /**
     * 成功 自定义其他数据
     *
     * @param data
     * @return
     */
    public static ResultData success(Object data) {
        return resultData(true, ResponseCode.SUCCESS.val(), ResponseCode.SUCCESS.msg(), data);
    }

    /**
     * 成功
     *
     * @return
     */
    public static ResultData success() {
        return resultData(true, ResponseCode.SUCCESS.val(), ResponseCode.SUCCESS.msg());
    }

    /**
     * 成功 自定义成功信息和其他数据
     *
     * @param data
     * @param msg
     * @return
     */
    public static ResultData success(Object data, String msg) {
        return resultData(true, ResponseCode.SUCCESS.val(), msg, data);
    }


    /**
     * 失败  自定义状态码和失败信息
     *
     * @param code
     * @param msg
     * @return
     */
    public static ResultData fail(String code, String msg) {
        return resultData(false, code, msg, null);
    }

    /**
     * 失败 自定义状态码和失败信息和其他数据
     *
     * @param code
     * @param msg
     * @param data
     * @return
     */
    public static ResultData fail(String code, String msg, Object data) {
        return resultData(false, code, msg, data);
    }

    /**
     * 失败
     *
     * @return
     */
    public static ResultData fail() {
        return resultData(false, ResponseCode.ERROR.val(), ResponseCode.ERROR.msg());
    }

    /**
     * 返回
     *
     * @param code 状态码
     * @param msg  信息
     * @param data 数据
     * @return 返回指定格式
     */
    private static ResultData resultData(boolean status, String code, String msg, Object data) {
        ResultData resultData = new ResultData();
        resultData.setStatus(status);
        resultData.setCode(code);
        resultData.setMsg(msg);
        resultData.setData(data);
        return resultData;
    }

    /**
     * 返回
     *
     * @param code 状态码
     * @param msg  信息
     * @return 返回指定格式
     */
    private static ResultData resultData(boolean status, String code, String msg) {
        ResultData resultData = new ResultData();
        resultData.setStatus(status);
        resultData.setCode(code);
        resultData.setMsg(msg);
        return resultData;
    }
}
